<?php

class wgText {
	
	public static function doFilter($text) {
		$text = trim(strip_tags($text));
		$text = eregi_replace("\n", ' ', $text);
		$text = eregi_replace("\r", ' ', $text);
		$text = eregi_replace("\t", ' ', $text);
		return preg_replace("/[ ]+/", ' ', $text);
	}
	
	public static function safeText($text) {
		return valid::safeText($text);
	}
	
	public static function secureSql($text) {
		return $text;
	}
	
	public static function secureSingleQuotes($text) {
		return ereg_replace("'", "\\'", $text);
	}
	
	public static function noHtmlAndEncodeBasics($text) {
		$text = strip_tags($text);
		$text = nl2br($text);
		return $text;
	}
	
	public static function safeName($text) {
		$text = self::safeText($text);
		$parts = explode('-', $text);
		foreach ($parts as $k=>$v) $parts[$k] = ucfirst($v);
		return implode(' ', $parts);
	}
	
	
	public static function getKeywordsArray($text) {
		$text = strtolower(self::doFilter($text));
		$arr = explode(' ', $text);
		$new = array();
		foreach ($text as $word) if (strlen($word) > 2) {
			if (isset($new[$word])) $new[$word]++;
			else $new[$word] = 1;
		}
		return $new;
	}
	
	public static function getTopKeywords($keywordArray, $limit=100) {
		$limit = (int) $limit;
		if (!(bool) $limit) $limit = 100;
		arsort($keywordArray);
		$x = 0;
		$new = array();
		foreach ($keywordArray as $word=>$num) {
			$new[] = $word;
			$x++;
			if ($x >= $limit) continue;
		}
		return $new;
	}
	
	public static function safeXmlText($text) {
		return htmlspecialchars(trim($text));
	}
	
	public static function lowercase($text) {
		return strtolower(trim($text));
	}
	
	public static function uppercase($text) {
		return strtoupper(trim($text));
	}
	
	public static function ucfirst($text) {
		return ucfirst(trim($text));
	}
	
	public static function decodeTemplate($text) {
		$text = eregi_replace('&', '&amp;', $text);
		$text = valid::decodeTemp(valid::decodeHTML($text));
		$text = eregi_replace('</textarea>', '&lt;/textarea&gt;', $text);
		return $text;
	}
	
	
	
	
	
}

?>